package com.deram.ctin.rest.web.controller.common;

import com.deram.ctin.common.utils.DateUtils;
import com.deram.ctin.common.utils.ValidateUtils;
import com.deram.ctin.dependencies.rest.base.BaseController;
import com.deram.ctin.serv.member.api.MemberFeedbackApi;
import com.deram.ctin.serv.member.entity.MemberFeedback;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;


@Api(tags = {"common - 投诉建议"})
@RestController
@RequestMapping("/common/feedBack")
public class CommonFeedBackController extends BaseController {

    @Autowired
    private MemberFeedbackApi memberFeedbackApi;

    @ApiOperation(value = "投诉建议")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "type", value = "投诉类型（0：内容异议，1：建议，2：其他）", required = true, paramType = "form"),
            @ApiImplicitParam(name = "content", value = "投诉内容", required = true, paramType = "form"),
            @ApiImplicitParam(name = "link", value = "联系方式", required = true, paramType = "form"),
    })
    @PostMapping("/saveFeedBack")
    public void saveFeedBack(Integer type, String content, String link) {
        String typeName = "";
        ValidateUtils.isMobile(link);
        ValidateUtils.notEmpty(content, "投诉内容");
        ValidateUtils.notNull(type, "投诉类型");
        switch (type) {
            case 0:
                typeName = "内容异议";
                break;
            case 1:
                typeName = "建议";
                break;
            case 2:
                typeName = "其他";
                break;
            default:
                typeName = "其他";
                break;
        }
        MemberFeedback memberFeedback = new MemberFeedback();
        memberFeedback.setContent(content);
        memberFeedback.setLink(link);
        memberFeedback.setType(type);
        memberFeedback.setTypeName(typeName);
        memberFeedback.setCreateDate(DateUtils.getNow());
        memberFeedbackApi.save(memberFeedback);
    }
}